// ColumnModels
var expertManageGrid_cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
			header : '专家ID',
			dataIndex : 'expertId',
			sortable : true,
			hidden : true,
			width : 50
		}, {
			header : '姓名',
			dataIndex : 'name',
			width : 100,
			sortable : true,
			locked : false
		}, {
			header : '身份证号',
			dataIndex : 'identityCardNumber',
			width : 140
		}, {
			header : '单位',
			dataIndex : 'unit',
			width : 140
		}, {
			header : '职称',
			dataIndex : 'jobTitle',
			width : 100
		}, {
			header : '专业',
			dataIndex : 'major',
			width : 100
		}, {
			header : '联系方式',
			dataIndex : 'contactInformation',
			width : 100
		}, {
			header : '单位地址',
			dataIndex : 'unitAddress',
			width : 140
		},{
			header : '家庭地址',
			dataIndex : 'homeAddress',
			width : 140	
		}, {
			header : '操作',
			dataIndex : 'expertId',
			renderer : expertAction,
			width : 200
		}])
function expertAction(value,cellmeta,record,rowIndex,columnIndex,store){
	change = "changeExpert('"+record.get("expertId")+ "','" + record.get("name") + "','" 
	+ record.get("identityCardNumber")+ "','" + record.get("unit")+"','"
		+ record.get("jobTitle")+"','" + record.get("major") + "','" 
			+ record.get("contactInformation")+ "','" + record.get("unitAddress")
				+ "','" + record.get("homeAddress")+ "');return false;";
    a = ' <a href="#" onclick="'+change+'">修改</a>&nbsp;';
    del = "deleteExpert('"+value+"');return false;";
    b = ' <a href="#" onclick="'+del+'">删除</a>&nbsp;';
	viewProject = "viewProjectInvolved('"+value+"');return false;";
    c = ' <a href="#" onclick="'+viewProject+'">查看参与验收的项目</a>&nbsp;';
    return a + b + c;
}
function deleteExpert(val){
	Ext.MessageBox.confirm("确认删除","你确认要删除所选专家吗？",function(btn){
		if(btn == "yes"){
			Ext.Ajax.request({
				url : 'expertManage/expertManageAction!deleteExpert',
				success : function(response,options){
	 				var r = Ext.decode(response.responseText);
	 				if(r.success){
	 					Ext.Msg.alert("操作成功","删除专家成功！");
	 					expertManageStore.reload();
	 				}else{
	 					Ext.Msg.alert("操作失败","请检查该专家是否有项目验收记录！");
	 				}
	 				
	 			},
	 			failure : function(){
	 				Ext.Msg.alert("操作失败","请重新操作！");
	 			},
				params : {
					'expertid' : val
				}
			});
		}
	});

}
var temp_expertWindow;
function changeExpert(expertid,name,identitycardnumber,unit,jobtitle,major,contactinformation,unitaddress,homeaddress){
	var expertWindow = new Ext.expertInfoWindow({
		width : 300,
		height : 330
	});
	temp_expertWindow = expertWindow;
	expertWindow.findById("expertid").setValue(expertid);
	expertWindow.findById("name").setValue(name);
	expertWindow.findById("identitycardnumber").setValue(identitycardnumber);
	expertWindow.findById("unit").setValue(unit);
	expertWindow.findById("jobtitle").setValue(jobtitle);
	expertWindow.findById("major").setValue(major);
	expertWindow.findById("contactinformation").setValue(contactinformation);
	expertWindow.findById("unitaddress").setValue(unitaddress);
	expertWindow.findById("homeaddress").setValue(homeaddress);
	expertWindow.show();
	//TODO:设置值 isDirty

}
var temp_projectInvolvedWindow;
function viewProjectInvolved(val){
	var projectInvolvedWindow = new Ext.pm.projectInvolvedWindow();
	temp_projectInvolvedWindow = projectInvolvedWindow;
	projectInvolvedWindow.grid.store.on('beforeload',function(){
		projectInvolvedWindow.grid.store.baseParams = {
				pageMessage1 : val,
				start : 0,
				limit : 20
		}
	});
	projectInvolvedWindow.grid.store.load({
		params : {
			pageMessage1 : val,
			start : 0,
			limit : 20
		}
	});
	projectInvolvedWindow.show();
}

Ext.expertManageGrid = Ext.extend(Ext.grid.GridPanel,{
	initialized:false,
	loadMask : true,
	loadData:function(){
	this.store.load({
		params:{
		start:0,
		limit:20
	}
	});
},
	initComponent:function(){
		this.store = expertManageStore;
		this.stripeRows = true; 
		this.cm = expertManageGrid_cm;
		this.tbar = [new Ext.inquryProjectExpertCombobox({
			id: 'pm_inquryProjectExpertCombobox_id',
			width : 100,
			listeners : {
				"select" : function(combo, record, number) {
					var a = combo.findParentBy(function(ct,cmp){
						return (ct instanceof Ext.grid.GridPanel) ? true : false;
					});
					a.getTopToolbar().findById("pm_inquryProjectExpertTextfield_id").setValue();
			
		        }
								
			}
		}),new Ext.inquryProjectTextfield({
			id : 'pm_inquryProjectExpertTextfield_id'
		}),new Ext.inquryProjectButton({
			id:'pm_inquryProjectExpertButton_id',
			handler : function(b,e){
			var a = b.findParentBy(function(ct, cmp) { 
				return (ct instanceof Ext.grid.GridPanel) ? true : false; 
			});
			var combo_value = a.getTopToolbar().findById("pm_inquryProjectExpertCombobox_id").getValue();
			var text_value = a.getTopToolbar().findById("pm_inquryProjectExpertTextfield_id").getValue();
			if(combo_value == "" && text_value == ""){
//				Ext.Msg.alert("请选择查询字段并输入查询文本!");
//				return;
			}else if(combo_value == ""){
				Ext.Msg.alert("请选择查询字段!");
				return;
			}else if(text_value == ""){
				Ext.Msg.alert("请输入查询文本!");
				return;
			}
				expertManageStore.on('beforeload',function(){
					expertManageStore.baseParams = {
							inquryText : text_value,
							type : combo_value
					}
				});
				expertManageStore.load({
					params : {
						start : 0,
						limit : 20,
						inquryText : text_value,
						type : combo_value
				}
				});
				
			
		}
		}),new Ext.Button({
			id : "pm_insertExpertButton_id",
			text : " 新增专家",
			handler : function(b,e){
				var insertExpertWindow = new Ext.expertInfoWindow({
					width : 300,
					height : 330,
					buttons : [{
				     	   xtype:'button',
				     	   text : '保存',
				     	   handler : function(){
							if(insertExpertWindow.findById("expertInfoFormPanel").form.isValid()&&insertExpertWindow.findById("expertInfoFormPanel").form.isDirty()){
								insertExpertWindow.findById("expertInfoFormPanel").form.submit({
									url : 'expertManage/expertManageAction!addExpert',
									params : {
										'expertid' : insertExpertWindow.findById("expertid").getValue(),
										'name' : insertExpertWindow.findById("name").getValue(),
										'identitycardnumber' : insertExpertWindow.findById("identitycardnumber").getValue(),
										'unit' : insertExpertWindow.findById("unit").getValue(),
										'jobtitle' : insertExpertWindow.findById("jobtitle").getValue(),
										'major' : insertExpertWindow.findById("major").getValue(),
										'contactinformation' : insertExpertWindow.findById("contactinformation").getValue(),
										'unitaddress' : insertExpertWindow.findById("unitaddress").getValue(),
										'homeaddress' : insertExpertWindow.findById("homeaddress").getValue()
									},
									success : function(form,action){
										Ext.Msg.alert("操作成功","新增专家成功!");
										expertManageStore.reload();
									
									},
									failure : function(form,action){
										Ext.Msg.alert("操作失败","请重新操作!");
									}
								});
							}
							else{
								Ext.Msg.alert("操作失败","请检查后重新操作!");
								return;
							}
							insertExpertWindow.close();
				        }
				        },{
				     	   xtype : 'button',
				     	   text : '关闭',
				     	   handler : function(b, e){
				        	insertExpertWindow.close();
				        }
				        }]
				});

				insertExpertWindow.show();
			}
		})];
		this.bbar = new Ext.PagingToolbar({
			pageSize : 20,
			store : this.store,
			displayInfo : true,
			displayMsg : '显示 {0}-{1}条 / 共 {2} 条',
			emptyMsg : "无数据。",
			plugins : [new Ext.ux.PageSizePlugin()],
			items : ['-']
		});
        Ext.expertManageGrid.superclass.initComponent.call(this);             
}
})
Ext.expertInfoWindow = Ext.extend(Ext.Window,{
	modal:true,
	initialized:false,
	layout : 'fit',
	buttonAlign : 'center',
	buttons : [{
     	   xtype:'button',
     	   text : '保存',
     	   handler : function(){
			if(temp_expertWindow.findById("expertInfoFormPanel").form.isValid()&&temp_expertWindow.findById("expertInfoFormPanel").form.isDirty()){
				temp_expertWindow.findById("expertInfoFormPanel").form.submit({
					url : 'expertManage/expertManageAction!updateExpert',
					params : {
						'expertid' : temp_expertWindow.findById("expertid").getValue(),
						'name' : temp_expertWindow.findById("name").getValue(),
						'identitycardnumber' : temp_expertWindow.findById("identitycardnumber").getValue(),
						'unit' : temp_expertWindow.findById("unit").getValue(),
						'jobtitle' : temp_expertWindow.findById("jobtitle").getValue(),
						'major' : temp_expertWindow.findById("major").getValue(),
						'contactinformation' : temp_expertWindow.findById("contactinformation").getValue(),
						'unitaddress' : temp_expertWindow.findById("unitaddress").getValue(),
						'homeaddress' : temp_expertWindow.findById("homeaddress").getValue()
					},
					success : function(form,action){
						Ext.Msg.alert("操作成功","成功修改专家信息!");
						expertManageStore.reload();
					
					},
					failure : function(form,action){
						Ext.Msg.alert("操作失败","请重新操作!");
					}
				});
			}
			temp_expertWindow.close();
        }
        },{
     	   xtype : 'button',
     	   text : '关闭',
     	   handler : function(b, e){
        	temp_expertWindow.close();
        }
        }],
        
	initComponent:function(){
	this.items = new Ext.form.FormPanel({
		id : 'expertInfoFormPanel',
//		style : 'padding-left: 30px;',
        shadow : true,
		border : false,
		layout:'form',
		height : 330,
		width : 500,
		items:[{
			id : 'expertid',
			name : 'expert.expertid',
			xtype : 'textfield',
			hidden : true
		},{
			id : 'name',
			name : 'expert.name',
			xtype : 'textfield',
			allowBlank : false,
			fieldLabel : '姓名'
		},{
			id : 'identitycardnumber',
			name : 'expert.identitycardnumber',
			xtype : 'textfield',
			allowBlank : false,
			fieldLabel : '身份证号'
		},{
			id : 'unit',
			name : 'expert.unit',
			xtype : 'textfield',
			fieldLabel : '单位'
		},{
			id : 'jobtitle',
			name : 'expert.jobtitle',
			xtype : 'textfield',
			fieldLabel : '职称'
		},{
			id : 'major',
			name : 'expert.major',
			xtype : 'textfield',
			fieldLabel : '专业'
		},{
			id : 'contactinformation',
			name : 'expert.contactinformation',
			xtype : 'textfield',
			fieldLabel : '联系方式'
		},{
			id : 'unitaddress',
			name : 'expert.unitaddress',
			xtype : 'textfield',
			fieldLabel : '单位地址'
		},{
			id : 'homeaddress',
			name : 'expert.homeaddress',
			xtype : 'textfield',
			fieldLabel : '家庭地址'
		}]});
	 	Ext.expertInfoWindow.superclass.initComponent.call(this);
}
})






Ext.pm.projectInvolvedWindow = Ext.extend(Ext.Window,{
	modal:true,
    title:'参与验收项目',
	cloasable : true,
	autoHeight : true,
	autoWidth : true,
	layout:'fit',
	buttonAlign: 'center',
	buttons : [{
	        	   xtype:'button',
	        	   text : '确定',
	        	   handler : function(){
					temp_projectInvolvedWindow.close();
	           }
	           },{
	        	   xtype : 'button',
	        	   text : '取消',
	        	   handler : function(b, e){
	        	   
	        	   	temp_projectInvolvedWindow.close();
	           }
	           }],
	initComponent : function(){
	var _reader = new Ext.data.JsonReader(
			{
				root : 'list',
				totalProperty : 'totalCount',
				id : 'id',
				successProperty : '@success'
			}, 
			[ {
				name : 'expertprojectid',
				mapping : 'expertprojectid'
			}, {
				name : 'expertid',
				mapping : 'expertid'
			}, {
				name : 'identitycardnumber',
				mapping : 'identitycardnumber'
			},{
				name : 'projectnumber',
				mapping : 'projectnumber'
			},{
				name : 'sparefield1',
				mapping : 'sparefield1'
			}, {
				name : 'sparefield2',
				mapping : 'sparefield2'
			}, {
				name : 'sparefield3',
				mapping : 'sparefield3'
			}]);
	
	
	var _store =  new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
            url: 'expertManage/expertManageAction!getProjectInvolved'
        }),
        pageSize : 20,
        reader : _reader
	});
		this.grid =  new Ext.grid.GridPanel({
			id:'projectInvolved_grid',
			store : _store,
			height : 300,
			width : 420,
			cm  :  new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(),
			{
				header : '项目编号',
				dataIndex : 'projectnumber',
				width : 100
			}, {
				header : '项目名称',
				dataIndex : 'sparefield1',
				width : 200
			}]),
			bbar :  new Ext.PagingToolbar({
				pageSize : 20,
				store : _store,
				displayInfo : true,
				displayMsg : '显示 {0}-{1}条 / 共 {2} 条',
				emptyMsg : "无数据。",
				plugins : [new Ext.ux.PageSizePlugin()],
				items : ['-']
			})
		});
		this.items = this.grid;

	Ext.pm.projectInvolvedWindow.superclass.initComponent.call(this);
}
});















